﻿using System;
using System.Diagnostics;
using System.IO;
using IWshRuntimeLibrary;

namespace Utility
{
    public static class ShortCut
    {
        public static void Create()
        {
            var fileName = Process.GetCurrentProcess().MainModule.FileName;
            var name = Path.GetFileNameWithoutExtension(fileName);
            if (!System.IO.File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\\{name}.lnk"))
            {
                IWshShortcut shortcut = new WshShell().CreateShortcut($"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\\{name}.lnk") as IWshShortcut;
                shortcut.TargetPath = fileName;
                shortcut.WorkingDirectory = Environment.CurrentDirectory;
                shortcut.Description = name;
                shortcut.Save();
            }
        }

        public static void Delete()
        {
            var filePath = $"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\\{Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName)}.lnk";
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
        }

        public static bool Exists()
        {
            return System.IO.File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Startup)}\\{Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().MainModule.FileName)}.lnk");
        }
    }
}
